<template>
	<view class="all">
		<view class="exam-info">

		</view>
		<view class="exam-record" v-if="flag">
			<view class="header">考试记录</view>
			<view class="uneame">
				<view class="avtar">
					<image class="avtar" src="https://xinguan-parent2.oss-cn-hangzhou.aliyuncs.com/index/face.jpg">
					</image>
					<image class="best" src="https://xinguan-parent2.oss-cn-hangzhou.aliyuncs.com/index/first.png">
					</image>
				</view>
				<text>最高历史成绩{{ highestscore }}分</text>
			</view>
			<view class="list">
				<view class="item" v-for="(item,index) in examList" :key="index" @click="goDetail(item.id)">
					<view class="score">{{ item.score }}<text>分</text></view>
					<view class="duration">{{ item.time | formatTimes }}</view>
					<view class="right fr">
						<view class="text" v-if="item.score == '100'">学神</view>
						<view class="text" v-else-if="'80' < (item.score) && (item.score) <= '99'">学霸</view>
						<view class="text" v-else-if="'50' < item.score && (item.score) <= '80'">乖乖</view>
						<view class="text" v-else-if="'0' <= item.score && (item.score) <= '50'">学渣</view>
						<view class="date">{{ item.date }}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="exam-record" v-else>
			暂无考试记录
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				flag: false,
				highestscore: '100',

				examList: [],
				id:null
			}
		},
		onLoad(params) {
				
			this.init()
		},
		methods: {
			init() {

				// var list = [{
				// 	id: 1,
				// 	name: '张三',
				// 	score: 123
				// }, {
				// 	id: 2,
				// 	name: '李四',
				// 	score: 135
				// }]



				
				// console.log(max);
				uni.$u.http.get('/app/paper/record').then((res) => {
					if (res.code == 0) {
						if (res.data.length > 0) {
							this.examList = res.data.reverse()

						
							
							this.highestscore = Math.max.apply(Math, this.examList.map(i => {
								return i.score
							}));
							this.flag = true
						} else {

						}

					}

				})
			},
			goDetail(id) {
				let newdata = {
					type: 3,
					id: id
				}
				//当你选中重现开始的时候就可以将用户的 作答计入删除并且，更新时间


				uni.navigateTo({
					url: './exam?id=' + JSON.stringify(newdata)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: linear-gradient(180deg, #FFFFFF 0%, #F5F5F5 100%);
		background-attachment: fixed;
	}

	.exam-record {
		position: relative;
		margin-top: 10px;
		background-color: #fff;
		padding: 0 50rpx;

		.header {
			font-size: 14px;
			color: #999;
			height: 40px;
			line-height: 40px;
			padding-left: 10px;
			border-bottom: 1px solid #f0f0f0;
		}

		.uneame {
			display: flex;
			height: 68px;
			padding: 0 25px 0 15px;

			.avtar {
				position: relative;
				width: 100px;
				height: 40px;
				margin-top: 5px;
				margin-left: 10px;

				.avtar {
					top: 0;
					left: 0px;
					width: 40px;
					height: 40px;
					border-radius: 25px;
				}

				.best {
					position: absolute;
					bottom: -10px;
					left: 0;
					width: 60px;
					height: 18px;

				}
			}

			text {
				font-size: 16px;
				color: #333;
				line-height: 68px;
			}
		}

		.list {
			position: relative;
			padding-left: 15px;
			padding-right: 10px;

			.item {
				display: flex;
				width: 100%;
				height: 50px;
				border-top: 1px solid #f0f0f0;
				margin-top: 50rpx;

				.score {
					display: block;
					font-size: 18px;
					color: #f25e5e;
					font-weight: 700;
					line-height: 50px;
					width: 30%;
					height: 70px;

					text {
						font-weight: normal;
						font-size: 14px;
					}
				}

				.duration {
					width: 40%;
					line-height: 50px;
					font-size: 14px;
					color: #999;
					padding-left: 20px;
					background: url(https://xinguan-parent2.oss-cn-hangzhou.aliyuncs.com/index/sj.png) left center no-repeat;
					background-size: 16px;
				}

				.right {
					width: 30%;
					text-align: right;

					.text {
						font-weight: 600;
						font-size: 14px;
						color: #f25e5e;
						line-height: 25px;
					}

					.date {
						font-size: 12px;
						color: #c7c7c7;
					}
				}
			}
		}
	}
</style>
